<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%request.setCharacterEncoding("utf-8"); %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
<c:if test="${mcTypeList==null && empty param.msg}">
	<c:redirect url="/Admin/McTypeManageServlet?fromPage=/Admin/Admin_Mctype.jsp"></c:redirect>
</c:if>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
	<title>ycnShop 管理中心 - 类别管理 </title>
	<link href="<c:url value="/Admin/styles/general.css" />" rel="stylesheet" type="text/css" />
	<link href="<c:url value="/Admin/styles/main.css" />" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<c:url value="/js/user.js" />"></script>
	<script language="javascript">
		var array_0=new Array();
		<c:forEach var="mcTypeMap" items="${mcTypeList}" varStatus="mStatus">
	  	<c:forEach var="me" items="${mcTypeMap}" >
	  		<c:set var="maxType" value="${me.key}" />
	  		<c:set var="minList" value="${me.value}"/>
		</c:forEach>
			array_0[${mStatus.index}]="${maxType.sname}"
			var array_${maxType.nid}=new Array();
			<c:forEach var="minType" items="${minList}" varStatus="lStatus">
	            array_${maxType.nid}[${lStatus.index}]="${minType.nid};${minType.sname}";
	      	</c:forEach>
		</c:forEach>
		
		function clickinputbgcolor(name){
			name.background='#BBDDE5';
			name.border='1px solid #dadada'
		}
		
		function clickinputbgcolor2(name){
			name.background='#ffffff';
			name.border='0px'
		}
		
		function checkUpdateType(nid,npid) {
			var sname = document.getElementById('typename_'+nid).value;
			var old_sname = document.getElementById('old_typename_'+nid).value;
			var arrayObj=eval("array_"+npid);
			var checkname= /[\u4e00-\u9fa5a-zA-Z0-9]+$/;
			if(sname.length==0) {
				alert('类别名不能为空');
				document.getElementById('typename_'+nid).focus();
				return;
			} else if(!checkname.test(sname)) {
				alert('类别名只能是汉字或英文字母或数字');
				document.getElementById('typename_'+nid).focus();
				return;
			} else if(old_sname==sname) {
				return;
			}
			for(i=0;i<arrayObj.length;i++) {
				if(arrayObj[i]==sname) {
				alert('该类别名已存在,请更换后重新提交');
				document.getElementById('typename_'+nid).focus();
				return;
				}
			}
			location.href="McTypeManageServlet?act=updateType&sname=" + sname + "&nid=" + nid + "&fromPage=/Admin/Admin_Mctype.jsp";
		}
		
		function checkDeleteType(nid,npid){
			if (confirm("您确定要删除此类别？\n\n删除类别后商品也一并删除！")) {
				location.href="McTypeManageServlet?act=deleteType&nid=" + nid + "&fromPage=/Admin/Admin_Mctype.jsp";
			}
		}
	</script>
    <c:if test="${not empty param.msg}">
    	<script language="javascript">
			alert('${param.msg}');
			location.href="McTypeManageServlet?fromPage=/Admin/Admin_Mctype.jsp"
		</script>
    </c:if>
</head>
<body>
<h1>
<span class="action-span"><a href="<c:url value="/Admin/Admin_Addtype.jsp" />">添加新类别</a></span>
<span><a href="#">Shop 管理中心</a>  - 类别管理 </span>
</h1>
<div class="list-div" id="listDiv">
<!--用户列表部分-->
<table cellpadding="0" cellspacing="1">
  <tr>
    <th>类别名称</th>
    <th>类别编号</th>
    <th>父类编号</th>
    <th>操作</th>
  </tr>
<c:forEach var="mcTypeMap" items="${mcTypeList}">
	<c:forEach var="me" items="${mcTypeMap}">
	<c:set var="maxType" value="${me.key}" />
	<c:set var="minList" value="${me.value}" />
	  <tr>
	    <td style="width:30%;padding-left:20px">
	    <img src="<c:url value='images/menu_minus.gif' />" alt="" style="cursor:hand;" />
	    <input type="hidden" name="old_typename_${maxType.nid}" value="${maxType.sname}" />
	    <input type="text" name="typename_${maxType.nid}" value="${maxType.sname}" onfocus="clickinputbgcolor(this.style);" onblur="clickinputbgcolor2(this.style);" style="font-weight:bold;padding:3px;height:12px;border:0px;" title="点击修改类别名称"/>
	    </td>
	    <td align="center" style="width:20%;">
			${maxType.nid}
		</td>
	    <td align="center" style="width:20%;">${maxType.npid}</td>
	    <td align="center" style="width:30%;">
	    <a href="#" onclick="checkUpdateType(${maxType.nid},${maxType.npid});return false;" >确认修改</a>&nbsp;&nbsp;&nbsp;
	    <a href="#" onclick="checkDeleteType(${maxType.nid},${maxType.npid});return false;" >删除分类</a>
	    </td>
	  </tr>
	<c:forEach var="minType" items="${minList}">
	  <tr>
	    <td style="padding-left:50px">
	    <img src="<c:url value='images/menu_arrow.gif' />" alt=""/>
	    <input type="hidden" name="old_typename_${minType.nid}" value="${minType.sname}" />
	    <input type="text" name="typename_${minType.nid}" value="${minType.sname}" onfocus="clickinputbgcolor(this.style);" onblur="clickinputbgcolor2(this.style);" style="padding:3px;height:12px;border:0px;" title="点击修改类别名称"/>
	    </td>
	    <td align="center">${minType.nid}</td>
	    <td align="center" >${minType.npid}</td>
	    <td align="center" >
	    <a href="#" onclick="checkUpdateType(${minType.nid},${minType.npid});return false;" >确认修改</a>&nbsp;&nbsp;&nbsp;
	    <a href="#" onclick="checkDeleteType(${minType.nid},${minType.npid});return false;" >删除分类</a>
	    </td>
	  </tr>
	</c:forEach>
	</c:forEach>
</c:forEach>
</table>
</div>
<div id="footer">版权所有 &copy;</div>
</body>
</html>
